home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: hearst.acc.Virginia.EDU!maxwell!gcl8a
- From: gcl8a@Virginia.EDU (Gregory Carl Lewin)
- Subject: More ?'s re: copy ctor
- Message-ID: <DMD0Kq.LHx@Virginia.EDU>
- Organization: University of Virginia
- Date: Tue, 6 Feb 1996 15:05:14 GMT
-
- When writing copy constructors for derived classes, it makes
- sense to use the existing copy ctor's for the base classes
- (thank you C++ FAQ's and everybody who responded to my question
- a month ago). However, I am confused about hoto do this with
- multiple inheritance. I have the following class tree:
-
- class Base {...}; //includes copy ctor
- class D1 : virtual Base (...}; //w/copy ctor
- class D2 : virtual Base {...}; //""
- class DD : public D1, public D2 {...};
-
- I have tried to write the copy ctor for DD as
-
- DD::DD(const DD& dd) : Base(dd), D1(dd), D2(dd)
- {...}
-
- Surprisingly, I do NOT get a compile error, which I expected
- because there should be no way to cast from DD to D2, right?
- (as in:
- void foo(D2* d2)
- will not accept:
-
- DD dd;
- foo(dd);
-
- right?
-
- I must admit I have not tried to run this code to see what
- happens. Can anyone explain it to me? Am I not as bright as
- my mother told me?
-
- Reply here or to:
- GCL8A@virginia.edu
-
- (pardon the syntax error in line 2)
-